home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Tools 1993 October - Disc 2
/
Power Tools (Disc 2)(October 1993)(HP).iso
/
superset
/
bin
/
calendar.mdl
< prev
next >
Wrap
Text File
|
1993-09-10
|
7KB
|
313 lines
%!
% PostScript program to draw calendar
% Copyright (C) 1987 by Pipeline Associates, Inc.
% Permission is granted to modify and distribute this free of charge.
% This program won't produce valid calendars before 1800 due to the switch
% from Julian to Gregorian calendars in September of 1752 wherever English
% was spoken.
/titlefont /NewCenturySchlbk-Bold def
/textfont /Helvetica-Narrow-BoldOblique def
/daynumfont /Helvetica-Narrow def
% calendar names - change these if you don't speak english
% "August", "April" and "February" could stand to be kerned even if you do
/month_names
[ (January ) (February ) (March ) (April ) (May ) (June ) (July )
(August ) (September ) (October ) (November ) (December ) ]
def
/day_names
[ (Sunday) (Monday) (Tuesday) (Wednesday) (Thursday) (Friday) (Saturday) ]
def
% layout parameters - you can change these, but things may not look nice
/daywidth 100 def
/dayheight 95 def
/monthfontsize 32 def
/titlefontsize 18 def
/textfontsize 21 def
/weekdayfontsize 14 def
/datefontsize 20 def
/topgridmarg 22 def
/leftmarg 30 def
/daytopmarg 0 def
/dayleftmarg 5 def
/daynamemargin 25 def
/monthmargin 40 def
% layout constants - don't change these, things probably won't work
/rows 5 def
/subrows 6 def
% calendar constants - change these if you want a French revolutionary calendar
/days_week 7 def
/days_month [ 31 28 31 30 31 30 31 31 30 31 30 31 ] def
/isleap { % is this a leap year?
year 4 mod 0 eq % multiple of 4
year 100 mod 0 ne % not century
year 1000 mod 0 eq or and % unless it's a millenia
} def
/ndays { % number of days in this month
days_month month 1 sub get
month 2 eq % February
isleap and
{
1 add
} if
} def
/weekday { % weekday (range 0-6) for integer date
days_week mod
} def
/startday { % starting day-of-week for this month
/off year 2000 sub def % offset from start of "epoch"
off
off 4 idiv add % number of leap years
off 100 idiv sub % number of centuries
off 1000 idiv add % number of millenia
6 add weekday days_week add % offset from Jan 1 2000
/off exch def
1 1 month 1 sub {
/idx exch def
days_month idx 1 sub get
idx 2 eq
isleap and
{
1 add
} if
/off exch off add def
} for
off weekday % 0--Sunday, 1--monday, etc.
} def
% ------------------------------------------------------------------------
/prtnum {
/width exch def
3 string cvs width right
} def
/right { % right justify string in given width
/width exch def
/str exch def
width str stringwidth pop sub 0 rmoveto str show
} def
/center { % center string in given width
/width exch def
/str exch def width str
stringwidth pop sub 2 div 0 rmoveto str show
} def
/centernum { exch 3 string cvs exch center } def
/drawgrid { % draw calendar boxes
titlefont findfont weekdayfontsize scalefont setfont
currentpoint /y0 exch def /x0 exch def
0 1 days_week 1 sub {
x0 y0 moveto
dup dup daywidth mul daynamemargin rmoveto
day_names exch get
daywidth center
x0 y0 moveto
daywidth mul topgridmarg rmoveto
1.0 setlinewidth
/rowsused rows 1 sub def
0 1 rowsused {
gsave
daywidth 0 rlineto
0 dayheight neg rlineto
daywidth neg 0 rlineto
closepath stroke
grestore
0 dayheight neg rmoveto
} for
} for
} def
/drawnums { % place day numbers on calendar
daynumfont findfont datefontsize scalefont setfont
/start startday def
/days ndays def
start daywidth mul dayleftmarg add daytopmarg rmoveto
1 1 days {
/day exch def
gsave
% Saturday?
day start add weekday 0 eq
{
.5 setgray
} if
% Sunday?
day start add weekday 1 eq
{
.5 setgray
} if
60 -65 rmoveto
isdouble
{
day prtdouble
}
{
day 30 prtnum
} ifelse
grestore
day start add weekday 0 eq
{
currentpoint exch pop dayheight sub 0 exch moveto
dayleftmarg 0 rmoveto
}
{
daywidth 0 rmoveto
} ifelse
} for
} def
/isdouble { % overlay today with next/last week?
days start add rows days_week mul gt
{
day start add rows days_week mul gt
{
true true
}
{
day start add rows 1 sub days_week mul gt
day days_week add days le and
{
false true
}
{
false
} ifelse
} ifelse
}
{
false
} ifelse
} def
/prtdouble {
gsave
daynumfont findfont datefontsize 2 mul 3 div scalefont setfont
exch
{
(23/) stringwidth pop dayheight rmoveto
2 prtnum
}
{
0 datefontsize 5 div rmoveto
2 prtnum
0 datefontsize -5 div rmoveto
gsave
daynumfont findfont datefontsize scalefont setfont
(/) show
grestore
} ifelse
grestore
} def
/drawfill { % place fill squares on calendar
/start startday def
/days ndays def
currentpoint /y0 exch def /x0 exch def
/fillstart 0 def
fillstart daywidth mul topgridmarg rmoveto
1.0 setlinewidth
fillstart 1 start 1 sub {
gsave
.99 setgray
daywidth 0 rlineto
0 dayheight neg rlineto
daywidth neg 0 rlineto
closepath fill
grestore
daywidth 0 rmoveto
} for
x0 y0 moveto
/lastday rows days_week mul def
days_week 1 sub daywidth mul
rows dayheight mul topgridmarg sub neg rmoveto
lastday -1 ndays start 1 add add
{
/day exch def
gsave
.99 setgray
daywidth 0 rlineto
0 dayheight rlineto
daywidth neg 0 rlineto
closepath fill
grestore
day weekday 1 eq
{
x0 y0 moveto
days_week 1 sub daywidth mul
rows dayheight mul topgridmarg sub neg rmoveto
}
{
daywidth neg 0 rmoveto
} ifelse
} for
} def
/daytext {
/text exch def
/lineno exch 1 sub def
/day exch startday add 1 sub def
/week day 7 idiv def
/dow day week 7 mul sub def
x0 y0 moveto
textfont findfont textfontsize scalefont setfont
/lineheight 30 def
dow daywidth mul dayleftmarg add
week dayheight mul lineno lineheight mul add neg rmoveto
text show
} def
/calendar
{
titlefont findfont monthfontsize scalefont setfont
/month_name month_names month 1 sub get def
/yearstring year 10 string cvs def
306 leftmarg add dayleftmarg 2 mul add
month_name stringwidth pop
yearstring stringwidth pop add 2 div sub monthmargin moveto
month_name show
yearstring show
0 -5 moveto
drawnums
0 -5 moveto
drawfill
0 -5 moveto
drawgrid
} def
/pagetitle {
gsave
titlefont findfont titlefontsize scalefont setfont
306 756 translate
name stringwidth pop 2 div neg 0 moveto
name show
grestore
} def